const app = getApp()
const db = wx.cloud.database()
Page({
  data: {
    wang:[
      {"name":"wangyichao"},
      { "name": "wangyi" },
      { "name": "wangchao" }
    ]
  },
  // to detail
  toDetail: function(e) {
    console.log(e)
    wx.navigateTo({
      url: '/pages/home/detail/detail?nav=' + 123,
    })
  },
  // to myself
  toMyself:function(){
    wx.navigateTo({
      url: '/pages/home/myself/myself',
    })
  },

  onLoad: function(options) {
    console.log("调用onload")
    console.log(wx.getSystemInfoSync().screenHeight)
    let that = this
    that.setData({
      winh: wx.getSystemInfoSync().screenHeight,
      tabbar: app.globalData.tabbar
    })
    db.collection('banner').where({}).get({
      success: res => {
        console.log('[数据库] [查询记录] 成功: ', res)
        that.setData({
          banner:res.data
        })
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '查询记录失败'
        })
        console.error('[数据库] [查询记录] 失败：', err)
      }
    })

  },

  onReady: function() {
    let that = this;
    let wang = that.data.wang;
    console.log(wang)
    wx.setStorage({
      key: 'wang',
      data: {
        wang: wang
      },
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    wx.getBatteryInfo({
      success:res => {
        console.log(res)
        console.log("1231312312132")
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    let that = this
    // 调用 onload
    that.onLoad()
    // 调用函数A
    that.shuaxin()
    // 调用函数B
    that.refresh()
    setTimeout(function(){
      wx.stopPullDownRefresh()
    },2000)
  },
  shuaxin:function(){
    console.log("调用函数A")
  },
  refresh(){
    console.log("调用函数B")
    
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})